<?php
session_start();
$subject_id=$_GET['subject_id'];
require_once('../include/connect.inc.php');
if($_SESSION['sess_id'] <> session_id()){
?>
 <SCRIPT LANGUAGE="JavaScript">
			alert("กรุณาเข้าสู่ระบบให้ถูกต้องตามขั้นตอน...!");
			location="login.php";
</script>
<?php }?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Model Test Program</title>
<link rel="stylesheet" type="text/css" href="../template/template_style_wood.css">
<script language=JavaScript type=text/javascript>
<!-- 
function CheckAll() {
for (var i = 0; i < document.messageList.elements.length; i++) {
if(document.messageList.elements[i].type == 'checkbox'){
document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);
}
}
}
//-->
</script>
</head>

<body>
<div id="menu"><div><img src="../images/icon-m.png" /></div>
<div id="menulinks">
		<a  href="../person_tea.php">ข้อมูลส่วนตัว</a>
		<a href="../tea_edit.php">เปลี่ยนรหัสผ่านใหม่</a>
        <a class="active"   href="show_subject.php">จัดการรายวิชา</a>
		<a href="../teacher_test.php">จัดการข้อสอบ</a>
        <a href="../teacher_tests.php">จัดการชุดข้อสอบ</a>
        <a  href="../agree_set.php">กำหนดสิทธิ์</a>
		<a href="../exam/tea_chack.php">ตรวจสอบคะแนน</a>
        <a href="../news/manage_news.php">ประกาศข่าวสาร</a>
        <a href="../problem/send_problem.php">แสดงความคิดเห็น</a>
        <a  href="../problem/teacher_message.php">กล่องข้อความ</a>
        <a href="../logout.php">ออกจากระบบ</a>
		</div></div>           
 <div id="p3">    
<div id="header"></div>
   <div id="page"><div id="p1">คุณ<?php echo $_SESSION['teacher_name'];?><hr/>
				<form name="messageList" id="messageList" method="post" action="agree_teacher_add.php">
					<table  border="0" cellspacing="0" cellpadding="0">
      					<tr>
        					<th align="left">ให้สิทธิ์วิชา <?php echo "$_GET[subject_name]";?></th>
        					<th align="right"><a href="insert_subject.php"> <img src="../images/add.png" border="0" /> </a> </th>
      					</tr>
    				</table>
					<table id="table" width="552" border="0" cellspacing="0" cellpadding="0">
  						<tr>
  						  <th width="44" align="center"><input type="checkbox" name="Button" id="checkbox" value="Select All" onClick=CheckAll(); ></th>
    						<th width="67" align="center">ลำดับที่</th>
    						<th width="113" align="center">รหัสประจำตัว</th>
    						<th width="231" align="center">ชื่อ-สกุล</th>
    						<th width="95" align="center">สิทธิ์ในรายวิชานี้</th>
  						</tr>
   						<?php
							$query  = query("SELECT * FROM tb_teacher ORDER BY r_teacher_id asc");
							$count	= 1;
							while ($rs = fetch_array($query)) {
								$r_teacher_id	  = $rs['r_teacher_id'];
		    					$the_teacher_name = $rs['teacher_fname']."  ".$rs['teacher_lname'];
						?>
  						<tr>
  						  <td align="center">
                          <?php
                          	$query2 = query("SELECT * FROM tb_agree_teacher where subject_id='$subject_id' AND r_teacher_id='$r_teacher_id' ");
									if(num_rows($query2)>0){
									echo "";
								}else{
							?>
                          	<input type="checkbox" name="r_teacher_id[]" id="r_teacher_id[]" value="<?php echo "$r_teacher_id"; ?>">
                            <?php }?>
                          </td>
    						<td align="center"><?php echo $count;echo ".";?></td>
    						<td align="center"><?php echo "$r_teacher_id";?></td>
    						<td align="center"><?php echo "$the_teacher_name";?></td>
    						<td align="center">
                            <?php 
							$query1 = query("SELECT * FROM tb_subject where subject_id='$subject_id' AND r_teacher_id='$r_teacher_id' ");
								if(num_rows($query1)>0){
									echo "อาจารย์ผู้สร้างวิชานี้ในระบบ";
									$query2 = query("SELECT * FROM tb_agree_teacher where subject_id='$subject_id' AND r_teacher_id='$r_teacher_id' ");
										}else if(num_rows($query2)<1){
											echo "ยังไม่ได้ให้สิทธิ์";
										}else{
							?>
                            <a href="agree_del_teacher.php?del_id=<?php echo "$r_teacher_id";?>&subject_id=<?php echo "$subject_id";?>">ถอนสิทธิ์</a>
                            <?php }?>
                            </td>
  						</tr>
						<?php 
  							$count++; 
							} 
						?>
					</table>
	                <p>
						<input type="hidden" name="subject_id" id="subject_id" value="<?php echo "$_GET[subject_id]";?>">
	                  <input type="submit" name="button" id="button" value="ให้สิทธิ์ในรายวิชานี้" />
                      <input type="reset" name="button2" id="button2" value="ยกเลิก" />
                  </p>
	  </form>
    </div>
    </div>
<div id="footer"></div>
</div>
</body>
</html>